<%-- 
  - Author: Mohtisham.Salahria
  - Date: 27-May-2011
  - Copyright Notice: TRAKHEES
  - Description: list.jsp
 --%>

<%@ include file="/WEB-INF/view/include.jsp"%>
<%@ page import="ae.pcfc.etks.online.web.*"%>


<c:choose>
	<c:when
		test='${requestScope.requestContextAttribute.locale.language == "ar"}'>
		<script language="Javascript" type="text/javascript"
			src='<c:url value="/resources/js/jqgrid/grid.locale-ar.js"/>'></script>
	</c:when>
	<c:otherwise>
		<script language="Javascript" type="text/javascript"
			src='<c:url value="/resources/js/jqgrid/grid.locale-en.js"/>'></script>
	</c:otherwise>
</c:choose>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.base.js"/>'></script>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.common.js"/>'></script>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.formedit.js"/>'></script>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.inlinedit.js"/>'></script>

<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.custom.js"/>'></script>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/jquery.fmatter.js"/>'></script>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.filter.js"/>'></script>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.jqueryui.js"/>'></script>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.import.js"/>'></script>
	
<script type="text/javascript">
    $.jgrid.no_legacy_api = true;
    $.jgrid.useJSON = true;
</script>
	
<script type="text/javascript">
	$()
			.ready(
					function() {

						$('#grid')
						.jqGrid(
								{
									datatype :'json',
									url		 :'${pageContext.request.contextPath}/admin/general/user/displayUserTable.json',
									height: 'auto', 
									colNames : [ '<spring:message code="label.id" />',
													'<spring:message code="label.nonclient.person.register.nameENG" />','<spring:message code="label.nonclient.person.register.nameARB" />','<spring:message code="label.nonclient.person.register.emailAddress" />', '<spring:message code="label.user.type" />', '<spring:message code="label.user.status" />'],
									
									colModel : [ {
										name:'UId',
										index : 'UId',
										width : 60,
										align : 'center'
									}, {
										name:'UNameEng',
										index : 'UNameEng',
										width : 400,
										align : 'center',
										sortable : true
									},{
										name:'UNameArb',
										index : 'UNameArb',
										width : 400,
										align : 'center',
										sortable : true
									} ,{
										name:'UEmail',
										index : 'UEmail',
										width : 400,
										align : 'center',
										sortable : true
									},{
										name:'UType',
										index : 'UType',
										width : 400,
										align : 'center',
										sortable : true
									},{
										name:'UStatus',
										index : 'UStatus',
										width : 400,
										align : 'center',
										sortable : true
									} ],
									rowNum:10, 
									autowidth: true, 
									viewrecords: true,
									rowList:[10,20,30], 
									 altRows:true,
							         altclass:'myAltRowClass',
									pager: jQuery('#pager'), 
									sortname: 'UNameEng', 
									viewrecords: true, 
									sortorder: "desc", 
									caption : '<spring:message code="label.nonclient.person.register.action.user" />'
									<c:if test='${requestScope.requestContextAttribute.locale.language == "ar"}'>
									, direction:'rtl'
									</c:if>									
								}).navGrid('#pager', {
							edit : false,
							add : false,
							del : false,
							search : true,
							searchtext:'<spring:message code="label.search" />'
						});
						$("#grid").navButtonAdd('#pager',
								   {  caption:'<spring:message code="label.button.add" />',
								    buttonicon:"ui-icon ui-icon-plus",
								    onClickButton: add,
								    position: "last",
								    title:'<spring:message code="label.add.user.internal.staff" />',
								    cursor: "pointer"
								   }
								  );
						$("#grid").navButtonAdd('#pager',
								   {  caption:'<spring:message code="label.edit" />',
								    buttonicon:"ui-icon ui-icon-pencil",
								    onClickButton: edit,
								    position: "last",
								    title:"",
								    cursor: "pointer"
								   }
								  );
		function add(){
			window.location = "${pageContext.request.contextPath}/admin/general/user/internal/form.htm";
		}
		function edit(){
			var row = $('#grid').jqGrid('getGridParam','selrow');
			if(row == null)
			{
				jAlert('error','<spring:message code="error.user.select" />', '<spring:message code="label.errormessage" />');	
			}
			else{
				var userType = $('#grid').jqGrid('getCell',row,'UType');
				if(userType == '<spring:message code="user.internal.staff" />'){
					window.location = "${pageContext.request.contextPath}/admin/general/user/internal/edit.htm?userId="+row;
				}else{
					window.location = "${pageContext.request.contextPath}/admin/general/user/edit.htm?userId="+row;
				}
			}
		}
		
		});
	
					
	
	
</script>
<%
	if(request.getAttribute(ConstantsAdmin.SUCCESS_PARAM) != null) {
%>
		<script type="text/javascript">
				$(document)
						.ready(
								function() {
									jAlert(
											'success','<%=request.getAttribute(ConstantsAdmin.SUCCESS_PARAM)%>',
											'<spring:message code="msg.success" />');
								});
			</script>			
		<%
						}
					%>
<div id="container" dir='<spring:message code="page.dir"/>'
	align='<spring:message code="page.align"/>'>
	<spring:hasBindErrors
		name="<%=ConstantsAdmin.ADMIN_UPDATE_USER_MODEL_KEY %>">
		<script type="text/javascript">
	$(document).ready(
			function() {
				jAlert('error', '<li><form:errors path="*" delimiter="<li>"/>',
						'<spring:message code="label.errormessage" />');
			});
</script>
	</spring:hasBindErrors>
				
		<div id="search"></div>
			<table id="grid">
			</table>
			<span id="pager"></span>
</div>